package com.ruoyi.refundInfo.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.businessOrder.domain.dto.RefundAuditDto;
import com.ruoyi.common.exception.ServiceException;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.refundInfo.domain.RefundInfo;
import com.ruoyi.refundInfo.service.IRefundInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 退款信息日志管理Controller
 * 
 * @author ruoyi
 * @date 2025-08-02
 */
@RestController
@Slf4j
@RequestMapping("/ruoyi/refundInfo")
public class RefundInfoController extends BaseController
{
    @Autowired
    private IRefundInfoService refundInfoService;



    /**
     * 查询退款信息日志管理列表
     */
//    @PreAuthorize("@ss.hasPermi('ruoyi:refundInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(RefundInfo refundInfo)
    {
        startPage();
        List<RefundInfo> list = refundInfoService.selectRefundInfoList(refundInfo);
        return getDataTable(list);
    }

    /**
     * 导出退款信息日志管理列表
     */
//    @PreAuthorize("@ss.hasPermi('ruoyi:refundInfo:export')")
    @Log(title = "退款信息日志管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RefundInfo refundInfo)
    {
        List<RefundInfo> list = refundInfoService.selectRefundInfoList(refundInfo);
        ExcelUtil<RefundInfo> util = new ExcelUtil<RefundInfo>(RefundInfo.class);
        util.exportExcel(response, list, "退款信息日志管理数据");
    }

    /**
     * 获取退款信息日志管理详细信息
     */
//    @PreAuthorize("@ss.hasPermi('ruoyi:refundInfo:query')")
    @GetMapping(value = "/{refundId}")
    public AjaxResult getInfo(@PathVariable("refundId") Long refundId)
    {
        return success(refundInfoService.selectRefundInfoByRefundId(refundId));
    }

    /**
     * 新增退款信息日志管理
     */
//    @PreAuthorize("@ss.hasPermi('ruoyi:refundInfo:add')")
    @Log(title = "退款信息日志管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RefundInfo refundInfo)
    {
        return toAjax(refundInfoService.insertRefundInfo(refundInfo));
    }

    /**
     * 修改退款信息日志管理
     */
//    @PreAuthorize("@ss.hasPermi('ruoyi:refundInfo:edit')")
    @Log(title = "退款信息日志管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RefundInfo refundInfo)
    {
        return toAjax(refundInfoService.updateRefundInfo(refundInfo));
    }

    /**
     * 删除退款信息日志管理
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:refundInfo:remove')")
    @Log(title = "退款信息日志管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{refundIds}")
    public AjaxResult remove(@PathVariable Long[] refundIds)
    {
        return toAjax(refundInfoService.deleteRefundInfoByRefundIds(refundIds));
    }

    /**
     * 查询当前订单的退款信息
     */
//    @PreAuthorize("@ss.hasPermi('refundInfo:refund:query')")
    @GetMapping("/getActiveRefundsByOrderId/{orderId}")
    public AjaxResult getActiveRefundsByOrderId(@PathVariable Long orderId)
    {
        List<RefundInfo> list = refundInfoService.selectActiveRefundsByOrderId(orderId);
        return AjaxResult.success(list);
    }

    /**
     * 获取最新的退款信息
     */
//    @PreAuthorize("@ss.hasPermi('refundInfo:refund:query')")
    @GetMapping("/getLatestRefundByOrderId/{orderId}")
    public AjaxResult getLatestRefundByOrderId(@PathVariable Long orderId)
    {
        RefundInfo refundInfo = refundInfoService.getLatestRefundByOrderId(orderId);
        return AjaxResult.success(refundInfo);
    }

    /**
     * 查询当前商品订单的退款信息
     */
//    @PreAuthorize("@ss.hasPermi('refundInfo:refund:query')")
    @GetMapping("/getActiveRefundsByGoodsOrderId/{goodsOrderId}")
    public AjaxResult getActiveRefundsByGoodsOrderId(@PathVariable Long goodsOrderId)
    {
        List<RefundInfo> list = refundInfoService.selectActiveRefundsByGoodsOrderId(goodsOrderId);
        return AjaxResult.success(list);
    }

    /**
     * 获取最新的退款信息，根据商品订单
     */
//    @PreAuthorize("@ss.hasPermi('refundInfo:refund:query')")
    @GetMapping("/getLatestRefundByGoodsOrderId/{goodsOrderId}")
    public AjaxResult getLatestRefundByGoodsOrderId(@PathVariable Long goodsOrderId)
    {
        RefundInfo refundInfo = refundInfoService.getLatestRefundByGoodsOrderId(goodsOrderId);
        return AjaxResult.success(refundInfo);
    }

}
